package com.huawei.hms.support.log;

import android.os.Process;
import android.util.Log;
import java.text.SimpleDateFormat;
import java.util.Locale;

public class c {
    private final StringBuilder a = new StringBuilder();
    private String b = null;
    private String c = "HMS";
    private int d = 0;
    private long e = 0;
    private long f = 0;
    private String g;
    private int h;
    private int i;
    private int j = 0;

    c(int i, String str, int i2, String str2) {
        this.j = i;
        this.b = str;
        this.d = i2;
        if (str2 != null) {
            this.c = str2;
        }
        c();
    }

    public static String a(int i) {
        switch (i) {
            case 3:
                return "D";
            case 4:
                return "I";
            case 5:
                return "W";
            case 6:
                return "E";
            default:
                return String.valueOf(i);
        }
    }

    private c c() {
        this.e = System.currentTimeMillis();
        Thread currentThread = Thread.currentThread();
        this.f = currentThread.getId();
        this.h = Process.myPid();
        StackTraceElement[] stackTrace = currentThread.getStackTrace();
        if (stackTrace.length > this.j) {
            StackTraceElement stackTraceElement = stackTrace[this.j];
            this.g = stackTraceElement.getFileName();
            this.i = stackTraceElement.getLineNumber();
        }
        return this;
    }

    public <T> c a(T t) {
        this.a.append(t);
        return this;
    }

    public c a(Throwable th) {
        a(Character.valueOf('\n')).a(Log.getStackTraceString(th));
        return this;
    }

    public String a() {
        StringBuilder stringBuilder = new StringBuilder();
        a(stringBuilder);
        return stringBuilder.toString();
    }

    private StringBuilder a(StringBuilder stringBuilder) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.getDefault());
        stringBuilder.append('[');
        stringBuilder.append(simpleDateFormat.format(Long.valueOf(this.e)));
        stringBuilder.append(' ').append(a(this.d)).append('/').append(this.c).append('/').append(this.b);
        stringBuilder.append(' ').append(this.h).append(':').append(this.f);
        stringBuilder.append(' ').append(this.g).append(':').append(this.i);
        stringBuilder.append(']');
        return stringBuilder;
    }

    public String b() {
        StringBuilder stringBuilder = new StringBuilder();
        b(stringBuilder);
        return stringBuilder.toString();
    }

    private StringBuilder b(StringBuilder stringBuilder) {
        stringBuilder.append(' ').append(this.a.toString());
        return stringBuilder;
    }

    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        a(stringBuilder);
        b(stringBuilder);
        return stringBuilder.toString();
    }
}
